# -*- coding: utf-8 -*-
import rsa
import os
# 先生成一对密钥，然后保存.pem格式文件，当然也可以直接使用
pubkey, privkey = rsa.newkeys(1024)

# 用公钥加密、再用私钥解密
f = open('C:/1.txt','rb')
message = f.read()
f.close()
os.remove('C:/1.txt')
crypto = rsa.encrypt(message, pubkey)
g = open('C:/1.abc','wb')
g.write(crypto)
#message = rsa.decrypt(crypto, privkey)


# sign 用私钥签名认证、再用公钥验证签名
#signature = rsa.sign(message, privkey, 'SHA-1')
#rsa.verify('lovesoo.org', signature, pubkey)